package com.tongcao.cn.stackoverflow;

import org.apache.commons.lang.exception.ExceptionUtils;

import java.util.Arrays;

/**
 * @Author:tongcao
 * @Date:2019/3/25 16:58
 * Description:
 */
public class ProgramSkills {

    public String getFullStackTrace(Throwable e) {
        // 方法1
        String trace = ExceptionUtils.getFullStackTrace(e);


        //方法2
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

        return trace;
    }


    /**
     * 输出数组
     * Arrays.deepToString与Arrays.toString不同之处在于，Arrays.deepToString更适合打印多维数组
     */
    public static void printArrayAsString() {
        int[] intArray = new int[]{1, 2, 3, 4, 5};
        System.out.println(Arrays.toString(intArray));

        String[] strArray = new String[]{"John", "Mary", "Bob"};
        System.out.println(Arrays.deepToString(strArray));
    }

    public static void main(String[] args) {
        printArrayAsString();
    }

    public String stackTraceToString(Throwable e) {
        StringBuilder sb = new StringBuilder();
        for (StackTraceElement element : e.getStackTrace()) {
            sb.append(element.toString());
            sb.append("\n");
        }
        return sb.toString();
    }
}
